package com.example.demo.form.User;

import com.example.demo.form.BaseForm;
import com.example.demo.model.entity.User;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotEmpty;

/**
 * @author: LKP
 * @create: 2020/11/25
 * @Description: 添加用户需要用的数据表单
 * @FileName: AddUserForm
 * @History:
 * @自定义内容：
 */
@Data
@ApiModel("添加用户需要的表单数据")
@EqualsAndHashCode(callSuper = false)
public class AddUserForm extends BaseForm<User> {

    /**
     * 姓名
     */
    @ApiModelProperty("姓名")
    @NotEmpty(message = "姓名不能为空")
    @Length(min = 1, max = 10, message = "姓名长度限制为1~10")
    private String name;

    /**
     * 年龄
     */
    @ApiModelProperty("年龄")
    @Range(min = 1, max = 150, message = "年龄大小为1~150")
    private Integer age;

    /**
     * 构造实体
     *
     * @return 实体对象
     */
    @Override
    public User buildEntity() {
        User user = new User();
        BeanUtils.copyProperties(this, user);
        return user;
    }

}
